package edu.gdin.ecommerce.dao;

import java.util.List;

import org.springframework.stereotype.Repository;


import edu.gdin.ecommerce.model.ParamDetail;
import edu.gdin.ecommerce.model.ParamType;
import edu.gdin.ecommerce.util.Pager;


@Repository("paramTypeDAO")
public class ParamTypeDAO extends BaseDAO {
	
	public Pager queryParamTypeByNameOrDesc(String name, String desc, int currentPage){
		
		String hql = "from ParamType p where 1=1 ";
		
		hql += name.equals("") ? "" : "and p.name like '%" + name +"%'";
		hql += desc.equals("") ? "" : "and p.typeDesc like '%" + desc +"%'";
		
		return	this.getPage(hql, currentPage);
	}

	public boolean saveParamType(ParamType type) {
		try{
			this.insert(type);
			return true;
		}
		catch(Exception e){
			return false;
		}
	}

	@SuppressWarnings("unchecked")
	public List<ParamType> queryAllTypes(){
		String hql = "from ParamType p";
		return  (List<ParamType>) this.query(hql);
	}
}
